package cc.co.cutenimy.nimyexplore.jdbc.driver.file;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;

import cc.co.cutenimy.nimyexplore.jdbc.driver.ClassPathLocation;
import cc.co.cutenimy.nimyexplore.jdbc.driver.DriverException;

public class FileJarLocation implements ClassPathLocation {
	private final File file;

	public FileJarLocation(String fileLocation) {
		file = new File(fileLocation);
		if (!file.exists()) {
			throw new IllegalArgumentException("File at: " + fileLocation
					+ " does not exist!");
		}
	}

	public FileJarLocation(File file) {
		if (file == null || !file.exists()) {
			throw new IllegalArgumentException("File at: "
					+ file.getAbsolutePath() + " does not exist!");
		}
		this.file = file;
	}

	public URL toURL() throws DriverException {
		try {
			return this.file.toURL();
		} catch (MalformedURLException e) {
			throw new DriverException(
					"FileJarLocation converted to URL failed.", e);
		}
	}

}
